package cho05;

/**
 * Created by 春旺 on 2017/4/3.
 */
//********************************************************************
 // FlipRace.java Java Foundations
 //
 // Demonstrates the reuse of programmer-defined class.
 //********************************************************************

 public class FilpRace {
    //-----------------------------------------------------------------
// Flips two coins until one of them comes up heads three times
// in a row.
//-----------------------------------------------------------------
    public static void main(String[] args) {
        final int GOAL = 3;
        int count1 = 0, count2 = 0;
        Coin53 coin1 = new Coin53(), coin2 = new Coin53();
        while (count1 < GOAL && count2 < GOAL) {
            coin1.flip();
            coin2.flip();
            System.out.println("Coin 1: " + coin1 + "\tCoin 2: " + coin2);
// Increment or reset the counters
            count1 = (coin1.isHeads()) ? count1 + 1 : 0;
            count2 = (coin2.isHeads()) ? count2 + 1 : 0;
        }
    }
}
